package com.example.mp4.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.mp4.mapper.UserMapper;
import com.example.mp4.pojo.User;
import jakarta.websocket.server.PathParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class UserController {

    @Autowired
    UserMapper userMapper;
//    @Autowired


    /*注册用户
    * */
    @PostMapping("/register")
    public String insertUser() {

        User user = new User();

        user.setId(1);
        user.setUsername("songliuguang");
        user.setPassword("123456");

        userMapper.insert(user);

        return "注册成功";

    }

    /*
    * 登录
    * */
    @GetMapping("/logintest")
    public  List<User> login(@PathParam("username")String username,@PathParam("password")String password) {
        String status="";
        int i=1;
//        User user =new User();
        List<User> all_user=userMapper.selectList(null);
        System.out.println(i++);



        return all_user;


    }



    @GetMapping("/logintest2/{username}/{password}")
    public  String loginok(@PathVariable("username") String username, @PathVariable("password") String password) {

//        User user =new User();

        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("username", username);
        queryWrapper.in("password", password);

        User user = userMapper.selectOne(queryWrapper); // 调用 selectOne 方法
        System.out.println("User: " + user);


//        List<User> all_user=userMapper.selectList(null);
//        System.out.println(i++);
//        user.setUsername(username);
//        user.setPassword(password);


//        status=userMapper.selectOne(user);



        return "success";


    }

}
